gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns #139080
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR complements and extends the work done in #138915.
In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword only patterns, the performance is much improved as it's no longer necessary to construct intermediary tuples so that's now only
~20%
slower compared to theif
equivalent. (Previously it was closer to~220%
).Further improvements can likely be archived if
MATCH_CLASS_GET_OPT_ATTR
is specialized in a similar manner toLOAD_ATTR
. With the specialization for (just)LOAD_ATTR
disabled, thematch
statement equivalent is again slightly faster than the correspondingif
clause.__
Micro benchmarks with all specializations enabled.
Micro benchmark (bare class pattern)
Micro benchmark (One keyword attribute)
📚 Documentation preview 📚: https://cpython-previews--139080.org.readthedocs.build/